package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.InStoreDTO;
import net.wanho.dto.PurchaseDTO;
import net.wanho.po.InStore;
import net.wanho.service.InStoreService;
import net.wanho.mapper.InStoreMapper;
import net.wanho.vo.InStoreVo;
import net.wanho.vo.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
* @author 王洋
* @description 针对表【in_store(入库单表)】的数据库操作Service实现
* @createDate 2024-09-03 17:43:36
*/
@Service
public class InStoreServiceImpl extends ServiceImpl<InStoreMapper, InStore>
    implements InStoreService{

    @Override
    public PageInfo<InStoreVo> inStorePageList(Integer pageNum, Integer pageSize, InStoreDTO inStoreDTO) {
        Page<InStoreVo> page = new Page<>(pageNum,pageSize);
        QueryWrapper<InStoreVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!ObjectUtils.isEmpty(inStoreDTO.getProductName()),"product_name",inStoreDTO.getProductName());
        queryWrapper.eq(!ObjectUtils.isEmpty(inStoreDTO.getStoreId()),"s.store_id",inStoreDTO.getStoreId());
        queryWrapper.between(ObjectUtils.isNotEmpty(inStoreDTO.getStartTime())&& ObjectUtils.isNotEmpty(inStoreDTO.getEndTime()),"i.create_time",inStoreDTO.getStartTime(),inStoreDTO.getEndTime());
        queryWrapper.ge(!ObjectUtils.isEmpty(inStoreDTO.getStartTime()), "i.create_time", inStoreDTO.getStartTime());
        queryWrapper.le(!ObjectUtils.isEmpty(inStoreDTO.getEndTime()), "i.create_time", inStoreDTO.getEndTime());
        this.baseMapper.selectByPage(page,queryWrapper);
        PageInfo<InStoreVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setLimitIndex((page.getCurrent()-1)*page.getSize());
        pageInfo.setResultList(page.getRecords());
        return pageInfo;

    }
}




